package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.busi.service.video.VideoService;
import com.cssw.fyzb.core.model.vo.video.VideoStatNumVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查询视频统计数量
 *
 * @author YangYiQun
 */
@Function(description = "查询视频统计信息", parameters = {
        @Parameter(name = "videoId", type = Type.Integer, description = "视频标识", required = true),
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = false),
}, result = @Result(properties = {
        @Property(name = "videoId", type = Type.Integer, description = "视频标识"),
        @Property(name = "likes", type = Type.Integer, description = "点赞数"),
        @Property(name = "comments", type = Type.Integer, description = "评论数"),
        @Property(name = "views", type = Type.Integer, description = "浏览数"),
        @Property(name = "shares", type = Type.Integer, description = "分享数"),
}))
@Component
public class GetVideoStatNum implements Action {

    @Autowired
    private VideoService videoService;

    private static final Logger logger = LoggerFactory.getLogger(GetVideoStatNum.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long videoId = request.getLong("videoId");
        try {
            VideoStatNumVo vo = videoService.getStatNum(videoId);
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
